﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BCGC.BLL.Helper;
using BCGC.BLL.MarketPlace;

public partial class Admin_MarketPlace_Default : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }

    private void BindData()
    {
        grvMarketPlaceList.DataSource = Market.GetAllMarketListing();
        grvMarketPlaceList.DataBind();
    }
    protected void grvMarketPlaceList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "cmdDelete")
        {

            if (Market.Delete(Convert.ToInt32(e.CommandArgument.ToString())))
            {
                uccResponse.SetSuccessMessage("MarketPlace successfuly Deleted");
            }
            else
            {
                uccResponse.SetFailMessage("Failed to delete MarketPlace");
            }
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        DateTime? dtFrom = null;
        if(!string.IsNullOrEmpty(txtFromDate.Text.Trim()))
        {
            dtFrom = Convert.ToDateTime(txtFromDate.Text.Trim());
        }

        DateTime? dtTo = null;
        if (!string.IsNullOrEmpty(txtToDate.Text.Trim()))
        {
            dtTo = Convert.ToDateTime(txtToDate.Text.Trim());
        }

        bool? isActive = null;

        if (ddlActive.SelectedItem.Value != "-1")
        {
            isActive = Convert.ToBoolean(ddlActive.SelectedItem.Value);
        }
        grvMarketPlaceList.DataSource = Market.GetAllMarketListing(txtUsername.Text.Trim(), dtFrom, dtTo, isActive,1,grvMarketPlaceList.PageSize);
        grvMarketPlaceList.DataBind();
    }
}
